﻿using Synapse.Framework.Notifier;
using Synapse.Framework.Pipe.BusinessObjects;

namespace Synapse.Framework.Pipe.PipeLines
{
    public class Filter<TInput, TPump> : IFilter<TInput, TPump>
    {
        private readonly IResolver resolver;
        private readonly PipeLine pipeLine;
        private readonly INotifier notifier;

        public Filter(IResolver resolver, PipeLine pipeLine, INotifier notifier)
        {
            this.resolver = resolver;
            this.pipeLine = pipeLine;
            this.notifier = notifier;
        }

        public Filter(IResolver resolver) : this(resolver,new PipeLine(), new TraceNotifier())
        {
        }

        public IOperation<TFilter, TInput, TPump> Pin<TFilter>()
        {
            return new OperationContainer<TFilter, TInput, TPump>(resolver, pipeLine, notifier);
        }

        public IOperation<TFilter, TInput, TPump> Pin<TFilter>(TFilter filter)
        {
            return new OperationInstance<TFilter, TInput, TPump>(resolver, pipeLine,filter,notifier);
        }

        public IOperationFunc<TInput, TPump> Pin()
        {
            return new OperationFunc<TInput, TPump>(resolver, pipeLine, notifier);
        }

        public void Push(TPump input)
        {
            pipeLine.Execute(new BusinessObjet<TPump>(input));
        }
    }
}